package guoanmaker.operator.business.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorEventDetails;

public interface OperatorEventDetailsRepository extends JpaRepository<OperatorEventDetails,String>,JpaSpecificationExecutor<OperatorEventDetails>{
	
	/**
	* @Title: selectEventAll 
	* @Description:查询所有活动
	* @param 
	* @return
	* @return OperatorEventDetails
	* @throws 
	 */
	@Query("select s from OperatorEventDetails s  where s.eventType = 1 and s.state <> '4' and s.state<> '0' and s.state <> 7")
	public List<OperatorEventDetails> selectEventAll();
	/**
	* @Title: updateStateDelete 
	* @Description:删除活动(修改状态为4)
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state = '4' where id = :id")
	public void updateStateDelete(@Param("id")String id);
	/**
	* @Title: updateEnrollmentAdd 
	* @Description:根据ID修参加活动人数
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set eventJoinPersonNum =eventJoinPersonNum+:num where id=:id ")
	public void updateEnrollmentBuyNumAdd(@Param("id") String activityId,@Param("num") Integer num);
	/**
	* @Title: updateEnrollmentAdd 
	* @Description:根据ID修参加活动人数
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set eventJoinPersonNum =eventJoinPersonNum+1 where id=:id ")
	public void updateEnrollmentAdd(@Param("id") String activityId);
	
	/**
	* @Title: updateEventStateFive 
	* @Description:报名中(修改状态为5)
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state = '5' where id = :id")
	public void updateEventStateFive(@Param("id") String id);
	
	/**
	* @Title: updateEventStateSix 
	* @Description:报名未开始(修改状态为6)
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state = '6' where id = :id")
	public void updateEventStateSix(@Param("id") String id);
	
	/**
	* @Title: updateEventStateSeven 
	* @Description:未生效(修改状态为7)
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set state = '7' where id = :id")
	public void updateEventStateSeven(@Param("id") String id);
	
	/**
	* @Title: updateEnrollmentRemove 
	* @Description: 根据ID修参加活动人数
	* @param id
	* @return 
	* @return 
	* @throws void
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set eventJoinPersonNum =eventJoinPersonNum-:num where id=:id ")
	public void updateEnrollmentRemove(@Param("id") String activityId,@Param("num") Integer num);
	/**
	* @Title: updateenrollment 
	* @Description: 根据ID修参加活动人数
	* @param id
	* @return   
	* @return 
	* @throws void
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set eventJoinPersonNum =:eventJoinPersonNum where id=:id ")
	public void updateenrollment(@Param("id") String activityId,@Param("eventJoinPersonNum") Integer eventJoinPersonNum);
	/**
	* @Title: updateStateZore 
	* @Description: 修改活动状态 未发布
	* @param id
	* @return 
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state = '0' where id = :id")
	public void updateStateZore(@Param("id")String id);
	/**
	* @Title: updateEventStarteOne 
	* @Description: 修改活动状态 未开始
	* @param id
	* @return  void
	* @return 
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set state = '1' where id = :id")
	public void updateEventStarteOne(@Param("id")String id);
	
	/**
	* @Title: updateEventStateTwo 
	* @Description: 修改活动状态 已开始
	* @param id
	* @return void
	* @return  
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails set state = '2' where id = :id")
	public void updateEventStateTwo(@Param("id")String id);
	/**
	 * lihongyu
	* @Title: updateEventEndTimeState 
	* @Description: 修改活动状态值  已结束
	* @param id
	* @return    void 
	* @return 
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state = '3' where id = :id")
	public void updateEventEndTimeState(@Param("id")String id);
	
	/**
	* @Title: endEvent 
	* @Description: 结束活动修改活动结束时间
	* @param id
	* @return     
	* @return void
	* @throws 
	 */
	@Transactional
	@Modifying
	@Query("update OperatorEventDetails s set s.eventEndTime = :eventEndTime ,s.state = '3' where s.id = :id ")
	public void endEvent(@Param("eventEndTime")Date eventEndTime,@Param("id")String id);
	/**
	 * 谁加的代码？lihongyu
	* @Title: getSelectEventByid 
	* @Description: 
	* @param id
	* @return
	* @return OperatorEventDetails
	* @throws 
	 */
	@Query("select s from OperatorEventDetails s where s.id = :id and s.state !=4")
	public OperatorEventDetails  getSelectEventByid(@Param("id") String id);
	
	
	/**
	* @Title: updateState
	* @Description:修改活动状态
	* @param id
	* @return
	* @return void
	* @throws 
	 */
	//@Transactional
	@Modifying
	@Query("update OperatorEventDetails  set state =:state where id =:id")
	public void updateStateByid(@Param("id")String id,@Param("state")Integer state);
	
}
